package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.dao.EcologyPoolRecordDao;
import com.sc.nft.dao.EcologyPoolSourceDayDao;
import com.sc.nft.entity.EcologyPoolSourceDay;
import com.sc.nft.service.EcologyPoolRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@RequiredArgsConstructor
@Service
public class EcologyPoolRecordServiceImpl implements EcologyPoolRecordService {
    private final EcologyPoolRecordDao ecologyPoolRecordDao;
    private final EcologyPoolSourceDayDao ecologyPoolSourceDayDao;

    @Override
    public void pointsBatch(List<EcologyPoolSourceDay> ecologyPoolSourceDays) {
        ecologyPoolSourceDays.forEach(ecologyPoolSourceDay -> {
            EcologyPoolSourceDay poolSourceDay = ecologyPoolSourceDayDao.getEcologyPoolSourceDay(ecologyPoolSourceDay.getLinkDate());
            if (BeanUtil.isEmpty(poolSourceDay)) {
                ecologyPoolSourceDayDao.save(ecologyPoolSourceDay);
            } else {
                ecologyPoolSourceDayDao.updateDateLinkCount(poolSourceDay.getId(), ecologyPoolSourceDay.getLinkCount());
            }
        });
    }
}
